// SPDX-License-Identifier: GPL-2.0
/*
 * Device Tree Source for the Porter board
 *
 * Copyright (C) 2015 Cogent Embedded, Inc.
 */

/*
 * SSI-AK4642
 *
 * JP3: 2-1: AK4642
 *      2-3: ADV7511
 *
 * This command is required before playback/capture:
 *
 *	amixer set "LINEOUT Mixer DACL" on
 */

/dts-v1/;
#include "r8a7791.dtsi"
#include <dt-bindings/gpio/gpio.h>

/ {
	model = "Porter";
	compatible = "renesas,porter", "renesas,r8a7791";

	aliases {
		serial0 = &scif0;
		i2c9 = &gpioi2c2;
		i2c10 = &i2chdmi;
	};

	chosen {
		bootargs = "ignore_loglevel rw root=/dev/nfs ip=on";
		stdout-path = "serial0:115200n8";
	};

	memory@40000000 {
		device_type = "memory";
		reg = <0 0x40000000 0 0x40000000>;
	};

	memory@200000000 {
		device_type = "memory";
		reg = <2 0x00000000 0 0x40000000>;
	};

	vcc_sdhi0: regulator-vcc-sdhi0 {
		compatible = "regulator-fixed";

		regulator-name = "SDHI0 Vcc";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		regulator-always-on;
	};

	vccq_sdhi0: regulator-vccq-sdhi0 {
		compatible = "regulator-gpio";

		regulator-name = "SDHI0 VccQ";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <3300000>;

		gpios = <&gpio2 12 GPIO_ACTIVE_HIGH>;
		gpios-states = <1>;
		states = <3300000 1
			  1800000 0>;
	};

	vcc_sdhi2: regulator-vcc-sdhi2 {
		compatible = "regulator-fixed";

		regulator-name = "SDHI2 Vcc";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		regulator-always-on;
	};

	vccq_sdhi2: regulator-vccq-sdhi2 {
		compatible = "regulator-gpio";

		regulator-name = "SDHI2 VccQ";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <3300000>;

		gpios = <&gpio2 26 GPIO_ACTIVE_HIGH>;
		gpios-states = <1>;
		states = <3300000 1
			  1800000 0>;
	};

	hdmi-out {
		compatible = "hdmi-connector";
		type = "a";

		port {
			hdmi_con: endpoint {
				remote-endpoint = <&adv7511_out>;
			};
		};
	};

	x3_clk: x3-clock {
		compatible = "fixed-clock";
		#clock-cells = <0>;
		clock-frequency = <148500000>;
	};

	x16_clk: x16-clock {
		compatible = "fixed-clock";
		#clock-cells = <0>;
		clock-frequency = <74250000>;
	};

	x14_clk: audio_clock {
		compatible = "fixed-clock";
		#clock-cells = <0>;
		clock-frequency = <11289600>;
	};

	sound {
		compatible = "simple-audio-card";

		simple-audio-card,format = "left_j";
		simple-audio-card,bitclock-master = <&soundcodec>;
		simple-audio-card,frame-master = <&soundcodec>;

		simple-audio-card,cpu {
			sound-dai = <&rcar_sound>;
		};

		soundcodec: simple-audio-card,codec {
			sound-dai = <&ak4642>;
			clocks = <&x14_clk>;
		};
	};

	gpioi2c2: i2c-9 {
		#address-cells = <1>;
		#size-cells = <0>;
		compatible = "i2c-gpio";
		status = "disabled";
		scl-gpios = <&gpio2 6 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
		sda-gpios = <&gpio2 7 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
		i2c-gpio,delay-us = <5>;
	};

	/*
	 * A fallback to GPIO is provided for I2C2.
	 */
	i2chdmi: i2c-10 {
		compatible = "i2c-demux-pinctrl";
		i2c-parent = <&i2c2>, <&gpioi2c2>;
		i2c-bus-name = "i2c-hdmi";
		#address-cells = <1>;
		#size-cells = <0>;

		ak4642: codec@12 {
			compatible = "asahi-kasei,ak4642";
			#sound-dai-cells = <0>;
			reg = <0x12>;
		};

		composite-in@20 {
			compatible = "adi,adv7180";
			reg = <0x20>;
			remote = <&vin0>;

			port {
				adv7180: endpoint {
					bus-width = <8>;
					remote-endpoint = <&vin0ep>;
				};
			};
		};

		hdmi@39 {
			compatible = "adi,adv7511w";
			reg = <0x39>;
			interrupt-parent = <&gpio3>;
			interrupts = <29 IRQ_TYPE_LEVEL_LOW>;

			adi,input-depth = <8>;
			adi,input-colorspace = "rgb";
			adi,input-clock = "1x";
			adi,input-style = <1>;
			adi,input-justification = "evenly";

			ports {
				#address-cells = <1>;
				#size-cells = <0>;

				port@0 {
					reg = <0>;
					adv7511_in: endpoint {
						remote-endpoint = <&du_out_rgb>;
					};
				};

				port@1 {
					reg = <1>;
					adv7511_out: endpoint {
						remote-endpoint = <&hdmi_con>;
					};
				};
			};
		};
	};
};

&extal_clk {
	clock-frequency = <20000000>;
};

&pfc {
	scif0_pins: scif0 {
		groups = "scif0_data_d";
		function = "scif0";
	};

	ether_pins: ether {
		groups = "eth_link", "eth_mdio", "eth_rmii";
		function = "eth";
	};

	phy1_pins: phy1 {
		groups = "intc_irq0";
		function = "intc";
	};

	pmic_irq_pins: pmicirq {
		groups = "intc_irq2";
		function = "intc";
	};

	sdhi0_pins: sd0 {
		groups = "sdhi0_data4", "sdhi0_ctrl";
		function = "sdhi0";
	};

	sdhi2_pins: sd2 {
		groups = "sdhi2_data4", "sdhi2_ctrl";
		function = "sdhi2";
	};

	qspi_pins: qspi {
		groups = "qspi_ctrl", "qspi_data4";
		function = "qspi";
	};

	i2c2_pins: i2c2 {
		groups = "i2c2";
		function = "i2c2";
	};

	usb0_pins: usb0 {
		groups = "usb0";
		function = "usb0";
	};

	usb1_pins: usb1 {
		groups = "usb1";
		function = "usb1";
	};

	vin0_pins: vin0 {
		groups = "vin0_data8", "vin0_clk";
		function = "vin0";
	};

	can0_pins: can0 {
		groups = "can0_data";
		function = "can0";
	};

	du_pins: du {
		groups = "du_rgb888", "du_sync", "du_disp", "du_clk_out_0";
		function = "du";
	};

	ssi_pins: sound {
		groups = "ssi0129_ctrl", "ssi0_data", "ssi1_data";
		function = "ssi";
	};

	audio_clk_pins: audio_clk {
		groups = "audio_clk_a";
		function = "audio_clk";
	};
};

&scif0 {
	pinctrl-0 = <&scif0_pins>;
	pinctrl-names = "default";

	status = "okay";
};

&ether {
	pinctrl-0 = <&ether_pins &phy1_pins>;
	pinctrl-names = "default";

	phy-handle = <&phy1>;
	renesas,ether-link-active-low;
	status = "okay";

	phy1: ethernet-phy@1 {
		reg = <1>;
		interrupt-parent = <&irqc0>;
		interrupts = <0 IRQ_TYPE_LEVEL_LOW>;
		micrel,led-mode = <1>;
	};
};

&sdhi0 {
	pinctrl-0 = <&sdhi0_pins>;
	pinctrl-names = "default";

	vmmc-supply = <&vcc_sdhi0>;
	vqmmc-supply = <&vccq_sdhi0>;
	cd-gpios = <&gpio6 6 GPIO_ACTIVE_LOW>;
	wp-gpios = <&gpio6 7 GPIO_ACTIVE_HIGH>;
	status = "okay";
};

&sdhi2 {
	pinctrl-0 = <&sdhi2_pins>;
	pinctrl-names = "default";

	vmmc-supply = <&vcc_sdhi2>;
	vqmmc-supply = <&vccq_sdhi2>;
	cd-gpios = <&gpio6 22 GPIO_ACTIVE_LOW>;
	status = "okay";
};

&qspi {
	pinctrl-0 = <&qspi_pins>;
	pinctrl-names = "default";

	status = "okay";

	flash@0 {
		compatible = "spansion,s25fl512s", "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <30000000>;
		spi-tx-bus-width = <4>;
		spi-rx-bus-width = <4>;
		m25p,fast-read;

		partitions {
			compatible = "fixed-partitions";
			#address-cells = <1>;
			#size-cells = <1>;

			partition@0 {
				label = "loader_prg";
				reg = <0x00000000 0x00040000>;
				read-only;
			};
			partition@40000 {
				label = "user_prg";
				reg = <0x00040000 0x00400000>;
				read-only;
			};
			partition@440000 {
				label = "flash_fs";
				reg = <0x00440000 0x03bc0000>;
			};
		};
	};
};

&i2c2 {
	pinctrl-0 = <&i2c2_pins>;
	pinctrl-names = "i2c-hdmi";

	clock-frequency = <400000>;
};

&i2c6 {
	pinctrl-names = "default";
	pinctrl-0 = <&pmic_irq_pins>;
	status = "okay";
	clock-frequency = <100000>;

	pmic@5a {
		compatible = "dlg,da9063l";
		reg = <0x5a>;
		interrupt-parent = <&irqc0>;
		interrupts = <2 IRQ_TYPE_LEVEL_LOW>;
		interrupt-controller;

		wdt {
			compatible = "dlg,da9063-watchdog";
		};
	};

	vdd_dvfs: regulator@68 {
		compatible = "dlg,da9210";
		reg = <0x68>;
		interrupt-parent = <&irqc0>;
		interrupts = <2 IRQ_TYPE_LEVEL_LOW>;

		regulator-min-microvolt = <1000000>;
		regulator-max-microvolt = <1000000>;
		regulator-boot-on;
		regulator-always-on;
	};
};

&sata0 {
	status = "okay";
};

&cpu0 {
	cpu0-supply = <&vdd_dvfs>;
};

/* composite video input */
&vin0 {
	status = "okay";
	pinctrl-0 = <&vin0_pins>;
	pinctrl-names = "default";

	port {
		vin0ep: endpoint {
			remote-endpoint = <&adv7180>;
			bus-width = <8>;
		};
	};
};

&pci0 {
	pinctrl-0 = <&usb0_pins>;
	pinctrl-names = "default";

	status = "okay";
};

&pci1 {
	pinctrl-0 = <&usb1_pins>;
	pinctrl-names = "default";

	status = "okay";
};

&hsusb {
	pinctrl-0 = <&usb0_pins>;
	pinctrl-names = "default";

	status = "okay";
};

&usbphy {
	status = "okay";
};

&pcie_bus_clk {
	clock-frequency = <100000000>;
};

&pciec {
	status = "okay";
};

&can0 {
	pinctrl-0 = <&can0_pins>;
	pinctrl-names = "default";

	status = "okay";
};

&du {
	pinctrl-0 = <&du_pins>;
	pinctrl-names = "default";
	status = "okay";

	clocks = <&cpg CPG_MOD 724>, <&cpg CPG_MOD 723>,
		 <&x3_clk>, <&x16_clk>;
	clock-names = "du.0", "du.1", "dclkin.0", "dclkin.1";

	ports {
		port@0 {
			endpoint {
				remote-endpoint = <&adv7511_in>;
			};
		};
	};
};

&lvds0 {
	ports {
		port@1 {
			lvds_connector: endpoint {
			};
		};
	};
};

&rcar_sound {
	pinctrl-0 = <&ssi_pins &audio_clk_pins>;
	pinctrl-names = "default";
	status = "okay";

	/* Single DAI */
	#sound-dai-cells = <0>;

	rcar_sound,dai {
		dai0 {
			playback = <&ssi0>;
			capture  = <&ssi1>;
		};
	};
};

&rwdt {
	timeout-sec = <60>;
	status = "okay";
};

&ssi1 {
	shared-pin;
};
